package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hulk.ratel.common.constant.enums.*;
import com.hulk.ratel.persistence.entity.TPartnerInfo;
import com.hulk.ratel.persistence.entity.TPartnerKey;
import com.hulk.ratel.persistence.repository.TPartnerInfoRepository;
import com.hulk.ratel.persistence.repository.TPartnerKeyRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2018/8/31 下午10:40
 * @Version: 1.0.0
 * @Modify by:
 * Class description
 */
@Slf4j
@Component
public class PartnerInfoCache {


    @Autowired
    private TPartnerInfoRepository partnerInfoRepository;

    /**
     * 合作方信息查询
     *
     * @param workId
     * @param partnerNo
     * @return
     */
    @Cached(key = "#partnerNo  + 'PartnerInfoCache_findPartnerInfo'", cacheType = CacheType.LOCAL ,localLimit = 1024, localExpire =600)
    public TPartnerInfo findPartnerInfo(String workId, @Nonnull String partnerNo) {
        TPartnerInfo param = new TPartnerInfo();
        param.setPartnerNo(partnerNo);
        param.setStatus(PartnerStatus.ENABLED.getValue());
        param.setArchivedFlag(ArchivedFlag.N.getValue());
        param.setAuditedFlag(AuditedFlag.Y.getValue());
        Wrapper<TPartnerInfo> queryPartnerWrapper = new EntityWrapper<>(param);
        return partnerInfoRepository.selectOne(queryPartnerWrapper);
    }
    
}
